<?php
require_once 'init-ise.php';

function htmlize(Station $station) {
	// defined days
	$html = "<ul><li>".$station->getStationname()."</li><li>".$station->getAddress()."</li>";
	$html .= "<li>Telefon: ".$station->getPhonenr()."</li><li>Offers:".implode(",",$station->getOffered())."</li>";
	$html .= "<li>Opening times</li><ul>";
	$days = array("MON","TUE","WED","THU","FRI","SAT","SUN");
	$hours = $station->getHours();
	foreach ($days as $day) {
		$html .= "<li>".$day." : ".$hours[$day]."</li>";
	}
	$html .= "</ul></ul>";
	return $html;
}
// for nav links
$url = $_SERVER['SCRIPT_NAME'];
// page parametes
if (isset($_GET['page'])) {
	$page = $_GET['page'];
} else {
	$page = 1;
} 
// prepare paging with 5 entries per page
$stations = StationQuery::create()->paginate($page,5);
?>
<html>
<head>
	<title>station list demo</title>
</head>
<body>
	<h1>STATION LIST</h1>
	<!-- navigation -->
	<fieldset>
		<?php 
		if (!$stations->isFirstPage()) {
			echo "<a href='".$url."?page=".$stations->getPreviousPage()."'>Prev</a>";
		}
		echo "<span>Page ".$stations->getPage()." of ".$stations->getLastPage()."</span>";
		if (!$stations->isLastPage()) {
			echo "<a href='".$url."?page=".$stations->getNextPage()."'>Next</a>";
		}
		?>
	</fieldset>
	<!-- retrieved list -->
	<ul>
		<?php 
		foreach ($stations as $station) {
			echo htmlize($station);
		}
		?>
	</ul>
</body>
</html>